Skip to content

refactor: use span helpers for byte views#102

Draft
l0rinc wants to merge 7 commits intomasterfrom
span-helpers-refactor
Draft

refactor: use span helpers for byte views#102
l0rinc wants to merge 7 commits intomasterfrom
span-helpers-refactor

Conversation

@l0rinc
Copy link
Copy Markdown
Owner

@l0rinc l0rinc commented Jan 17, 2026

  • Standardize byte/span conversions to the project’s helpers to reduce manual casts and make intent clearer.

  • Reduce repeated boilerplate for spans and bytes without changing behavior.

  • Add a focused test that locks in the mainnet genesis scriptSig bytes, so the consensus critical genesis construction can be refactored safely.

  • Replace ad hoc byte/span conversions with MakeByteSpan, MakeWritableByteSpan, MakeUCharSpan, UCharCast, and SpanPopBack.

  • Switch genesis timestamp bytes to MakeUCharSpan(std::string_view{...}) with no change to output.

This hard codes the expected coinbase `scriptSig` hex.

This protects consensus-critical genesis construction against refactors.
This is equivalent to the prior `std::vector<unsigned char>` built from `pszTimestamp` and `strlen`.

It preserves the exact byte sequence while avoiding raw pointer casts.
Add util tests for `MakeByteSpan`, `MakeWritableByteSpan`, `MakeUCharSpan`, `UCharCast`, and `SpanPopBack`.

This is equivalent to `std::as_bytes(std::span{...})` on the same input.
This is equivalent to `std::as_writable_bytes(std::span{...})` for the same container.

It removes manual span construction without changing the bytes read.
This is equivalent to the prior `reinterpret_cast<unsigned char*>` usage.

It centralizes the cast helper without changing the pointer value.
This is equivalent to the prior explicit span construction and casts.

It keeps the same bytes while using the shared helper.
This is equivalent to `span.first(span.size() - 1)` for the same input.

It makes the intent explicit without changing behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant